package com.ssy.lingxi.member.merchant.serviceimpl.web;

import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationAddVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationDeleteVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationGetVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationUpdateVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberOrgTreeVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberOrganizationQueryVO;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberCacheService;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberOrganizationService;
import com.ssy.lingxi.member.merchant.service.web.IMemberAbilityOrganizationService;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 会员能力 - 会员组织机构服务实现类
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-28
 */
@Service
public class MemberAbilityOrganizationServiceImpl implements IMemberAbilityOrganizationService {

    @Resource
    private IBaseMemberCacheService memberCacheService;

    @Resource
    private IBaseMemberOrganizationService baseMemberOrganizationService;

    @Override
    public Wrapper<Void> addMemberOrg(HttpHeaders headers, MemberOrganizationAddVO addVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.addMemberOrg(loginUser.getMemberId(), addVO);
    }

    /**
     * 根据菜单Id，更新组织机构信息
     *
     * @param headers HttpHeaders信息
     * @param updateVO 接口参数
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> updateMemberOrg(HttpHeaders headers, MemberOrganizationUpdateVO updateVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.updateMemberOrg(loginUser.getMemberId(), updateVO);
    }

    /**
     * 删除一个会员组织架构
     *
     * @param headers HttpHeaders信息
     * @param deleteVO 接口参数
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> deleteMemberOrg(HttpHeaders headers, MemberOrganizationDeleteVO deleteVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.deleteMemberOrg(loginUser.getMemberId(), deleteVO);
    }

    /**
     * 查询一个会员组织架构
     *
     * @param headers HttpHeaders信息
     * @param getVO 接口参数
     * @return 操作结果
     */
    @Override
    public Wrapper<MemberOrganizationQueryVO> getMemberOrg(HttpHeaders headers, MemberOrganizationGetVO getVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.getMemberOrg(loginUser.getMemberId(), getVO);
    }

    /**
     * 查询会员的所有组织架构，以树形菜单的形式返回
     * @param headers HttpHeaders信息
     * @return 操作结果
     */
    @Override
    public Wrapper<List<MemberOrgTreeVO>> treeMemberOrg(HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.treeMemberOrg(loginUser.getMemberId());
    }

    /**
     * 查询会员的（非门店）所有组织架构，以树形菜单的形式返回
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @Override
    public Wrapper<List<MemberOrgTreeVO>> nonStoreTreeMemberOrg(HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberOrganizationService.nonStoreTreeMemberOrg(loginUser.getMemberId());
    }
}
